package com.lightheart.sphr.xiaobinggan.timeselection.uitls

import com.lightheart.sphr.xiaobinggan.app.DCApplication
import com.lightheart.sphr.xiaobinggan.timeselection.listener.TimerListener
import com.lightheart.sphr.xiaobinggan.utils.CircleProgressBar

/**
 *    Author :hongliang
 *    E-mail : 13717858152@163.com
 *    Date   : 2021/1/1811:39 AM
 *    Desc   :
 *    Version: 1.0.0
 */
class TimerManager {
    private var timer: MyCountDownTimer = MyCountDownTimer(0)
    private var isStart = false
    private lateinit var progressBar: CircleProgressBar

    companion object {
        val instance: TimerManager by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) {
            TimerManager()
        }
    }

    fun setListener(listener: TimerListener): TimerManager {
        timer.setTimerListener(listener)
        return this
    }

//    fun setProgressView(progressBar: CircleProgressBar): TimerManager {
//        this.progressBar = progressBar
//        timer.setTimerListener()
//        return this
//    }


    fun startTimer() {
//        if (isStart || !Constant.isLogin(MainApplication.getInstance()))
//            return
        timer.setHasTime(DCApplication.getReadTime())
        timer.start()
        isStart = true
    }

    fun stopTimer(hasTime: Int) {
        DCApplication.setReadTime(hasTime * 1000L)
        timer.cancel()
        isStart = false
    }

}